<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="./adminHead.jsp"%>
<html>
<head>
    <title>分类添加</title>
    <style type="text/css">
        .mySpan{
            font-size: 20px;
        }
        .myText{
            height: 50px;
            width: 400px;
            font-size: 15px;
        }
        .myBt{
            height: 50px;
            width: 100px;
        }
    </style>
    <script type="text/javascript">
        function verificationId(){
            $.post({
                url:"${pageContext.request.contextPath}/jsp/admin/class.do?method=verification",
                dataType: "text",
                async: false,
                data:{"bookCode":$("#bookCode").val()},
                success:function (data) {
                    if(data=="true"){
                        $("#bookInfo").css("color","green");
                        $("#bookInfo").html("此书可以添加分类");
                    }else{
                        $("#bookInfo").css("color","red");
                        $("#bookInfo").html("并无此书，无法添加分类");
                    }
                }
            });
        }
        function confirm(){
            verificationId();
            var colorRes = $("#bookInfo").css("color");
            console.log(colorRes);
            if(colorRes == "rgb(0, 128, 0)"){
                return true;
            }else {
                alert("编号异常！")
                return false;
            }
        }
    </script>
</head>
<body>
<div class="col-md-9">
    <div class="row text-center" style="font-size: 20px">
        <c:if test="${tips != null}">
            <div class="alert alert-success" role="alert">
                <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
                <span class="sr-only">Yes:</span>${tips}
            </div>
        </c:if>
        <c:if test="${error != null}">
            <div class="alert alert-danger" role="alert">
                <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
                <span class="sr-only">Error:</span>${error}
            </div>
        </c:if>
    </div>
    <form action="${pageContext.request.contextPath}/jsp/admin/class.do?method=add" method="post">
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <span class="mySpan">编号：</span>
                    <input type="text" class="form-control myText" id="bookCode" name="bookCode" placeholder="请输入编号" value="${book.id}" onblur="verificationId()" required/>
                    <span class="mySpan" id="bookInfo"></span>
                </div>
                <div class="form-group">
                    <span class="mySpan">分类：</span>
                    <input type="text" class="form-control myText" id="bookClass" name="bookClass" placeholder="请输入新添加的分类" value="" required/>
                </div>
            </div>
            <div class="col-md-6">

            </div>
        </div>
        <div class="row">
            <div class="col-md-4">
                <div class="col-md-6">
                    <input type="submit" class="btn btn-lg btn-primary myBt" value="添加" onclick="return confirm()"/>
                </div>
                <div class="col-md-6">
                    <input type="reset" class="btn btn-lg btn-primary myBt" value="重置"/>
                </div>
            </div>

        </div>
    </form>

</div>

</body>
</html>